package ui;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import data.QuerySolutionInfo;

public class QueryNameUi extends Dialog {

	protected QuerySolutionInfo result = new QuerySolutionInfo();
	protected Shell shell;
	private Text txtName;
	private Text txtMark;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public QueryNameUi(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public QuerySolutionInfo open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(331, 181);
		shell.setText(getText());
		
		shell.setLocation(Display.getCurrent().getClientArea().width / 2 - shell.getShell().getSize().x/2, Display.getCurrent()
				.getClientArea().height / 2 - shell.getSize().y/2);
		
		Label label = new Label(shell, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("楷体", 12, SWT.BOLD));
		label.setBounds(97, 10, 129, 15);
		label.setText("\u8F93\u5165\u65B9\u6848\u540D\u79F0\uFF1A");
		
		Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				result.setName(txtName.getText());
				result.setMark(txtMark.getText());
				shell.dispose();
			}
		});
		button.setBounds(235, 119, 80, 25);
		button.setText("\u786E\u5B9A");
		
		txtName = new Text(shell, SWT.BORDER);
		txtName.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 9, SWT.NORMAL));
		txtName.setBounds(37, 31, 278, 21);
		
		Label label_1 = new Label(shell, SWT.NONE);
		label_1.setText("\u8F93\u5165\u5907\u6CE8\uFF1A");
		label_1.setFont(SWTResourceManager.getFont("楷体", 12, SWT.BOLD));
		label_1.setBounds(97, 58, 129, 15);
		
		txtMark = new Text(shell, SWT.BORDER);
		txtMark.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 9, SWT.NORMAL));
		txtMark.setBounds(37, 82, 278, 21);

	}
}
